﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mogre.TutorialFramework;
using Mogre;
using System.IO;
using System.Timers;

namespace ProjetInfoMogre
{
	public class Monde
	{
		protected static Root mRoot;
		protected RenderWindow mRenderWindow;
        public SceneManager mSceneMgr;
        public Camera mCamera;
        public CameraMan mCameraMan;
        public Camera camera_entite;
        public static float mDeltaTime;
        public bool MessageVisible; // Message affiché par F1

		protected int nbRobots;
		protected int nbOgres; 
		public List<Ogre> Ogres;
		public List<Robot> Robots;
        public List<Node> Cubes;
        public int indice =0;
        public int compteur_cube;
        public Robot mon_robot; // Robot controllé
        public Entity cercle;
        public SceneNode noeud_cercle;

		public Entity statueOgre; 
		public SceneNode statueOgreNode;
		public int tailleStatue;
        protected int tailleAttaque=5;
		private float tailleZoneOnde = 600f; 

        public MOIS.InputManager mInputMgr;
        public MOIS.Keyboard mKeyboard;
        public MOIS.Mouse mMouse;

        Random random = new Random();

        public float time;

		public Monde(int _nbOgres, int _nbRobots)
		{
            nbOgres = _nbOgres;
            nbRobots = _nbRobots;
			
            Ogres = new List<Ogre>();
            Robots = new List<Robot>();
            Cubes = new List<Node>();

			try
			{
                Initialisation();
                CreateFrameListeners();
                EnterRenderLoop();

			}
			catch (OperationCanceledException) 
		    { 
				Console.WriteLine("un problème est apparu, veuillez relancer le projet");
			}
		}

        protected void Initialisation()
        {
            mRoot = new Root();

            // Define Ressources
            ConfigFile cf = new ConfigFile();
            cf.Load("resources.cfg", "\t:=", true);

            var section = cf.GetSectionIterator();
            while (section.MoveNext())
            {
                foreach (var line in section.Current)
                    ResourceGroupManager.Singleton.AddResourceLocation(line.Value, line.Key, section.CurrentKey);
            }

            // Create Render System
            if (!mRoot.ShowConfigDialog())
                throw new OperationCanceledException();

            // Create Render Window
            mRenderWindow = mRoot.Initialise(true, "Main Ogre Window");

            // Initialise Ressources
            TextureManager.Singleton.DefaultNumMipmaps = 5;
            ResourceGroupManager.Singleton.InitialiseAllResourceGroups();

            // Initialise Input
            var inputParams = new MOIS.ParamList();
            IntPtr windowHnd;
            mRenderWindow.GetCustomAttribute("WINDOW", out windowHnd);
            inputParams.Insert("WINDOW", windowHnd.ToString());

            mInputMgr = MOIS.InputManager.CreateInputSystem(inputParams);

            mKeyboard = (MOIS.Keyboard)mInputMgr.CreateInputObject(MOIS.Type.OISKeyboard, true);
            mMouse = (MOIS.Mouse)mInputMgr.CreateInputObject(MOIS.Type.OISMouse, true);

            mKeyboard.KeyPressed += new MOIS.KeyListener.KeyPressedHandler(OnKeyPressed);
            mKeyboard.KeyReleased += new MOIS.KeyListener.KeyReleasedHandler(OnKeyReleased);
            mMouse.MouseMoved += new MOIS.MouseListener.MouseMovedHandler(OnMouseMoved);
            mMouse.MousePressed += new MOIS.MouseListener.MousePressedHandler(OnMousePressed);
            mMouse.MouseReleased += new MOIS.MouseListener.MouseReleasedHandler(OnMouseReleased);

            // Create a scene
            CreateScene();
        }

		protected  void CreateScene()
		{
            CreateCamera();

            mSceneMgr.AmbientLight = new ColourValue(0.6f,0.6f,0.6f);
            mSceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE;

            // Création du sol
            Plane plane = new Plane(Vector3.UNIT_Y, 0);
            MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 3000, 3000, 20, 20, true, 1, 5, 5, Vector3.UNIT_Z);
            Entity groundEnt = mSceneMgr.CreateEntity("GroundEntity", "ground");
            mSceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(groundEnt);
            groundEnt.SetMaterialName("Examples/Sable");
            groundEnt.CastShadows = false;

            // Création du sous-sol
            Plane ocean = new Plane(Vector3.UNIT_Y, 0);
            MeshManager.Singleton.CreatePlane("Ocean", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, ocean, 15000, 15000, 20, 20, true, 1, 5, 5, Vector3.UNIT_Z);
            Entity groundOcean = mSceneMgr.CreateEntity("Ocean", "Ocean");
            mSceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(groundOcean);
            groundOcean.SetMaterialName("Examples/TextureEffect2");
            groundOcean.CastShadows = false;
            groundOcean.ParentNode.Translate(new Vector3(0, -10, 0));

            // Création des zones 
            Plane zone1 = new Plane(Vector3.UNIT_Y, 0);
            MeshManager.Singleton.CreatePlane("Zone1", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, zone1, 1000, 1000, 20, 20, true, 1, 5, 5, Vector3.UNIT_Z);
            Entity Zone_B = mSceneMgr.CreateEntity("Zone1", "Zone1");
            mSceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(Zone_B);
            Zone_B.SetMaterialName("Examples/Terrain");
            Zone_B.CastShadows = false;
            Zone_B.ParentNode.Translate(new Vector3(-1000, 1, 1000));

            Plane zone2 = new Plane(Vector3.UNIT_Y, 0);
            MeshManager.Singleton.CreatePlane("Zone2", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, zone2, 1000, 1000, 20, 20, true, 1, 5, 5, Vector3.UNIT_Z);
            Entity Zone_S = mSceneMgr.CreateEntity("Zone2", "Zone2");
            mSceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(Zone_S);
            Zone_S.SetMaterialName("Examples/Terrain");
            Zone_S.CastShadows = false;
            Zone_S.ParentNode.Translate(new Vector3(1000, 1, -1000));	
			
            // Création de la statue d'ogre
			statueOgre = mSceneMgr.CreateEntity("statue", "Sinbad.mesh");
            statueOgreNode = mSceneMgr.RootSceneNode.CreateChildSceneNode("StatueNode", new Vector3(-1000, 254, 1000));
			statueOgreNode.Scale(new Vector3(45.0f, 45.0f, 45.0f));
			statueOgre.SetMaterialName("Examples/Rocky");
			statueOgreNode.AttachObject(statueOgre);
			statueOgre.CastShadows = false;

			// Rotation de la statue
			Vector3 src = statueOgreNode.Orientation * Vector3.UNIT_X;
            Quaternion quat = src.GetRotationTo(new Vector3(-1, 0, -1));
			statueOgreNode.Rotate(quat);

			//ajout de la source de lumière sur la statue
			Light pointLight = mSceneMgr.CreateLight("pointLight");
            pointLight.Type = Light.LightTypes.LT_POINT;
			pointLight.Position = new Vector3(-950, 500, 950);
			pointLight.DiffuseColour = ColourValue.White;


            // Création de la zone de tir de la statue
            cercle = mSceneMgr.CreateEntity("Cercle", "cylinder.mesh");
            noeud_cercle = mSceneMgr.RootSceneNode.CreateChildSceneNode("CercleNode", new Vector3(-1000, 2, 1000));
            cercle.SetMaterialName("Examples/FlyingLightMaterial");
            noeud_cercle.Scale(new Vector3(0.2f, 600f, 600f));
            noeud_cercle.Rotate(new Vector3(0, 0, 1), 3.14f / 2);
            noeud_cercle.AttachObject(cercle);
            cercle.CastShadows = false;

            // Création des murs
            CreerMur("MurDerriere", new Plane(new Vector3(-1, 0, 0), 0), new Vector3(1500, 50, 0));
            CreerMur("MurFace", new Plane(new Vector3(1, 0, 0), 0), new Vector3(-1500, 50, 0));
            CreerMur("MurGauche", new Plane(new Vector3(0, 0, 1), 0), new Vector3(0, 50, 1500));
            CreerMur("MurDroite", new Plane(new Vector3(0, 0, -1), 0), new Vector3(0, 50, -1500));            

            // Création du ciel
			Light directionalLight = mSceneMgr.CreateLight("directionalLight");
			directionalLight.Type = Light.LightTypes.LT_DIRECTIONAL;
			directionalLight.DiffuseColour = ColourValue.White;
			directionalLight.SpecularColour = ColourValue.White;
			directionalLight.Direction = new Vector3(0, -30, 30);
            mSceneMgr.SetSkyDome(true, "Examples/CloudySky", 5, 2);

			//Création des cubes
			 for (int i = 0; i <=nbOgres*2; i++)
			 {                
			     Entity cube = mSceneMgr.CreateEntity("Cube"+i, "cube.mesh");
			     SceneNode noeud_cube = mSceneMgr.RootSceneNode.CreateChildSceneNode("CubeNode" + i, new Vector3(random.Next(550, 1450), 10, random.Next(-1450, -550)));
			     cube.SetMaterialName("Examples/Rockwall");

			     noeud_cube.Scale(new Vector3(0.25f, 0.25f, 0.25f));
			     noeud_cube.AttachObject(cube);
			     cube.CastShadows = false;

			     Cubes.Add(noeud_cube);
                 compteur_cube = i;
			}

           CreerEntite();
		}
        protected void CreateCamera()
        {
            mSceneMgr = mRoot.CreateSceneManager(SceneType.ST_GENERIC);
            mCamera = mSceneMgr.CreateCamera("PlayerCam");
            mCamera.AutoAspectRatio = true;
            mRenderWindow.AddViewport(mCamera);

            mCamera.Position = new Vector3(0, 750, -2000);
            mCamera.LookAt(Vector3.ZERO);
            // Distance au-dessus et en-dessous de laquelle on ne voit plus rien
            mCamera.NearClipDistance = 5;

            mCameraMan = new CameraMan(mCamera);
           
        }
        public void CreerEntite()
        {
            int totalEntite = nbRobots + nbOgres;
            
            for (int i = 0; i < totalEntite; i++)
            {
                Entite ent;
                if (i < nbRobots)
                {
					float distanceF;
					Vector3 vecteur_position;
					do
					{
						vecteur_position = new Vector3(random.Next(-1500, 1500), 0, random.Next(-1500, 1500));
						Vector3 distance = statueOgreNode.Position - vecteur_position;
						distanceF = distance.Normalise();
					} while (distanceF <= 300f);
                    ent = new Robot(mSceneMgr, vecteur_position,this);
                    Robots.Add((Robot)ent);
                }
                else
                {
                    Vector3 vecteur_position = new Vector3(random.Next(-1500, 1500), 22, random.Next(-1500, 1500));
					ent = new Ogre(mSceneMgr, vecteur_position, this);
                    Ogres.Add((Ogre)ent);
                }
            }
        }
        public void CreerMur(string NomPlan, Plane plane, Vector3 position) 
        {
            MeshManager.Singleton.CreatePlane(NomPlan, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 3000, 200, 20, 20, true, 1, 6, 1f, new Vector3(0, 1, 0));
            Entity entityMur = mSceneMgr.CreateEntity(NomPlan, NomPlan);
            mSceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(entityMur);
            entityMur.SetMaterialName("Examples/Bois");
            entityMur.ParentNode.Translate(position);
            entityMur.CastShadows = false;
        }


		#region Overlays
		public void Info()
        {
            var messageBox = OverlayManager.Singleton.GetOverlayElement("InfoOverlay/MessageBox");
            messageBox.Left = (mRenderWindow.Width - messageBox.Width) / 2;
            messageBox.Top = (mRenderWindow.Height - messageBox.Height) / 2;

            var messageBody = OverlayManager.Singleton.GetOverlayElement("InfoOverlay/MessageBox/Body");
            messageBody.Caption = "Aide :\n\nF1 : Fermer la fenetre\nF2 : Recentrer la camera\nF3 : Prendre le controle d'un robot\nF4 : Ajouter un robot\nF5 : Ajouter un ogre\nF6 : Ajouter un cube\nEspace : Accelerer la vitesse de la camera\nEchap : Quitter l'application";
            OverlayManager.Singleton.GetByName("InfoOverlay").Show();
        }
        public void Message()
        {
            var messageBox = OverlayManager.Singleton.GetOverlayElement("MessageOverlay/MessageBox");
            messageBox.Left = mRenderWindow.Width - 210;
            messageBox.Top = mRenderWindow.Height - 90;

            var messageBody = OverlayManager.Singleton.GetOverlayElement("MessageOverlay/MessageBox/Body");
            messageBody.Caption = "Nombre de robots : " + Robots.Count() + "\nNombre d'ogres : " + Ogres.Count() + "\nNombre de cubes : " + Cubes.Count() + "\nStatue level :     " + (int)tailleStatue/5;
            OverlayManager.Singleton.GetByName("MessageOverlay").Show();
        }
		#endregion

        protected void CreateFrameListeners()
        {
            mRoot.FrameRenderingQueued += new FrameListener.FrameRenderingQueuedHandler(OnFrameRenderingQueued);
        }       
		bool OnFrameRenderingQueued(FrameEvent evt)
        {
            ProcessInput();
            Message();
    
            mCameraMan.UpdateCamera(time);

            //Gestion des Entités
            time = evt.timeSinceLastFrame;
            for (int i = 0; i < Robots.Count; i++)
			{
				Robots[i].vit(time);
			}
			for (int i = 0; i < Ogres.Count; i++)
			{
				Ogres[i].vit(time);
			}
			//gestion de la statue
			this.statueAttaque();
            return true;
        }
        protected static void EnterRenderLoop()
        {
            mRoot.StartRendering();
        }

        // Gestion de la caméra
        protected void ProcessInput()
        {
            mKeyboard.Capture();
            mMouse.Capture();
        }


		public void Control_Robot()
		{
			//Robots.Remove(mon_robot);

			mon_robot.Walking = false;

			mKeyboard.KeyPressed += new MOIS.KeyListener.KeyPressedHandler(RobotOnKeyPressed);
			mKeyboard.KeyReleased += new MOIS.KeyListener.KeyReleasedHandler(RobotOnKeyReleased);
			//mMouse.MouseMoved += new MOIS.MouseListener.MouseMovedHandler(RobotOnMouseMoved);

			Vector3 Move = Vector3.ZERO;



			mKeyboard.Capture();
			mMouse.Capture();


			// Attention nous sommes en QUERTY
			// if (mon_robot.Noeud.Position.x < 1500 && mon_robot.Noeud.Position.x > -1500 && mon_robot.Noeud.Position.z > -1500 && mon_robot.Noeud.Position.z < 1500)
			//{
			if (mKeyboard.IsKeyDown(MOIS.KeyCode.KC_NUMPAD8)) //gestion de la touche "Z"
			{
				Console.WriteLine("touche Z");
				mon_robot.Ent.GetAnimationState("Walk").AddTime(mDeltaTime);
				Move.x += 100f;
			}
			if (mKeyboard.IsKeyDown(MOIS.KeyCode.KC_NUMPAD2))//gestion de la touche "S"
			{
				mon_robot.Ent.GetAnimationState("Walk").AddTime(mDeltaTime);
				Move.x -= 100f;
			}
			if (mKeyboard.IsKeyDown(MOIS.KeyCode.KC_NUMPAD4))//gestion de la touche "Q"
			{
				mon_robot.Ent.GetAnimationState("Walk").AddTime(mDeltaTime);
				Move.z -= 100f;
			}
			if (mKeyboard.IsKeyDown(MOIS.KeyCode.KC_NUMPAD6))//gestion de la touche "D"
			{
				mon_robot.Ent.GetAnimationState("Walk").AddTime(mDeltaTime);
				Move.z += 100;
			}
			//}

			if (mKeyboard.IsKeyDown(MOIS.KeyCode.KC_E))
				mon_robot.Noeud.Rotate(new Vector3(0, 1, 0), -0.005f);
			if (mKeyboard.IsKeyDown(MOIS.KeyCode.KC_Q))
				mon_robot.Noeud.Rotate(new Vector3(0, 1, 0), 0.005f);
			mon_robot.Noeud.Yaw((float)(-mMouse.MouseState.X.rel * mDeltaTime));
			mon_robot.Noeud.Translate(Move * mDeltaTime, Node.TransformSpace.TS_LOCAL);

		}


		#region gestion touches
		protected virtual bool OnKeyPressed(MOIS.KeyEvent evt)
        {
            if (mCamera.Position.x >= 1500)
                mCamera.Position = new Vector3(1500, mCamera.Position.y, mCamera.Position.z);

            if (mCamera.Position.z >= 1500)
                mCamera.Position = new Vector3(mCamera.Position.x, mCamera.Position.y, 1500);
            if (mCamera.Position.x <= -1500)
                mCamera.Position = new Vector3(-1500, mCamera.Position.y, mCamera.Position.z);

            if (mCamera.Position.z <= -1500)
                mCamera.Position = new Vector3(mCamera.Position.x, mCamera.Position.y, -1500);


            switch (evt.key)
            {
                case MOIS.KeyCode.KC_W:
                case MOIS.KeyCode.KC_UP:
                    mCameraMan.GoingForward = true;
                    break;

                case MOIS.KeyCode.KC_S:
                case MOIS.KeyCode.KC_DOWN:
                    mCameraMan.GoingBack = true;
                    break;

                case MOIS.KeyCode.KC_A:
                case MOIS.KeyCode.KC_LEFT:
                    mCameraMan.GoingLeft = true;
                    break;

                case MOIS.KeyCode.KC_D:
                case MOIS.KeyCode.KC_RIGHT:
                    mCameraMan.GoingRight = true;
                    break;

                case MOIS.KeyCode.KC_E :
                case MOIS.KeyCode.KC_PGUP:
                    if( mCamera.Position.y < 4000)
                        mCameraMan.GoingUp = true;
                    break;

                case MOIS.KeyCode.KC_Q:
                case MOIS.KeyCode.KC_PGDOWN:
                    if (mCamera.Position.y > 260)
                    mCameraMan.GoingDown = true;
                    break;

                case MOIS.KeyCode.KC_SPACE:    // Accélère la caméra
                    mCameraMan.FastMove = true;
                    break;

                case MOIS.KeyCode.KC_F1:
                    if (MessageVisible == false)
                    {
                        this.Info();
                        MessageVisible = true;
                    }
                    else if (MessageVisible == true)
                    {
                        OverlayManager.Singleton.GetByName("InfoOverlay").Hide();
                        MessageVisible = false;
                    }
                    break;

                case MOIS.KeyCode.KC_F2:    // Recentre la camera
                    mRenderWindow.RemoveAllViewports();
                    mRenderWindow.AddViewport(mCamera);
                    mCamera.Position = new Vector3(0, 750, -2000);
                    mCamera.LookAt(Vector3.ZERO);
                    break;

                case MOIS.KeyCode.KC_F3:    // Prend le control d'un robot
                    camera_entite = new Camera("camera_robot", mSceneMgr);
                    camera_entite.Position = new Vector3(-150, 150, 0);
                    camera_entite.LookAt(new Vector3(0,90,0));
                    mon_robot = Robots[indice];
                    mon_robot.Noeud.AttachObject(camera_entite);
                    mRenderWindow.RemoveAllViewports();
                    mRenderWindow.AddViewport(camera_entite);
                    Control_Robot(); //Permet de gerer les mouvements du robot selectionné

                    if (Robots.Count()-1 == indice)
                        indice=0;
                    else
                        indice++;
                    break;

                case MOIS.KeyCode.KC_F4:    // Ajoute un robot
                    Robot Nouveau_robot = new Robot(mSceneMgr, new Vector3(random.Next(-1500, 1500), 0, random.Next(-1500, 1500)), this);
                    Robots.Add(Nouveau_robot);
                    break;

                case MOIS.KeyCode.KC_F5:    // Ajoute un ogre
                    Ogre Nouveau_ogre = new Ogre(mSceneMgr, new Vector3(random.Next(-1500, 1500), 22, random.Next(-1500, 1500)), this);
                    Ogres.Add(Nouveau_ogre);
                    break;

                case MOIS.KeyCode.KC_F6:    // Ajoute un bloc
                    compteur_cube++;
                    Entity Nouveau_cube = mSceneMgr.CreateEntity("Nouveau_Cube"+compteur_cube, "cube.mesh");
			        SceneNode noeud_cube = mSceneMgr.RootSceneNode.CreateChildSceneNode("Nouveau_CubeNode"+compteur_cube , new Vector3(random.Next(550, 1450), 10, random.Next(-1450, -550)));
			        Nouveau_cube.SetMaterialName("Examples/Rockwall");

			        noeud_cube.Scale(new Vector3(0.25f, 0.25f, 0.25f));
			        noeud_cube.AttachObject(Nouveau_cube);
			        Nouveau_cube.CastShadows = true;

			        Cubes.Add(noeud_cube);
                    break;

                // Quitter le programme
                case MOIS.KeyCode.KC_ESCAPE:
                    mRoot.QueueEndRendering();
                    break;
            }
            return true;
        }

       
        protected virtual bool OnKeyReleased(MOIS.KeyEvent evt)
        {
            switch (evt.key)
            {
                case MOIS.KeyCode.KC_W: //gestion de la touche "Z"
                case MOIS.KeyCode.KC_UP:
                    mCameraMan.GoingForward = false;
                    break;

                case MOIS.KeyCode.KC_S: //gestion de la touche "S"
                case MOIS.KeyCode.KC_DOWN:
                    mCameraMan.GoingBack = false;
                    break;

                case MOIS.KeyCode.KC_A: //gestion de la touche "Q"
                case MOIS.KeyCode.KC_LEFT:
                    mCameraMan.GoingLeft = false;
                    break;

                case MOIS.KeyCode.KC_D: //gestion de la touche "D"
                case MOIS.KeyCode.KC_RIGHT:
                    mCameraMan.GoingRight = false;
                    break;

                case MOIS.KeyCode.KC_E: //gestion de la touche "E"
                case MOIS.KeyCode.KC_PGUP:
                    mCameraMan.GoingUp = false;
                    break;

                case MOIS.KeyCode.KC_Q: //gestion de la touche "A"
                case MOIS.KeyCode.KC_PGDOWN:
                    mCameraMan.GoingDown = false;
                    break;

                case MOIS.KeyCode.KC_F1:
                    mCameraMan.FastMove = false;
                    break;
            }
            mCameraMan.UpdateCamera(time);
            return true;
        }
        protected virtual bool OnMouseMoved(MOIS.MouseEvent evt)
        {
            mCameraMan.MouseMovement(evt.state.X.rel, evt.state.Y.rel);
            return true;
        }
        protected virtual bool OnMousePressed(MOIS.MouseEvent evt, MOIS.MouseButtonID id)
        {
            return true;
        }
        protected virtual bool OnMouseReleased(MOIS.MouseEvent evt, MOIS.MouseButtonID id)
        {
            return true;
        }

        protected virtual bool RobotOnKeyPressed(MOIS.KeyEvent evt)
        {
            Vector3 Move = Vector3.ZERO;
            switch (evt.key)
            {
                case MOIS.KeyCode.KC_NUMPAD8:
                    Console.WriteLine("touche 8");
                    Move.x -= 100f;
                    mon_robot.Ent.GetAnimationState("Walk").AddTime(mDeltaTime);
                    mon_robot.Destination = Move;
                     
                    break;
            }
		

            
            return true;
        }

		#endregion

		protected virtual bool RobotOnKeyReleased(MOIS.KeyEvent evt)
        {

            switch (evt.key)
            {
                case MOIS.KeyCode.KC_NUMPAD8:
                    Console.WriteLine("touche 8");
                    mon_robot.Ent.GetAnimationState("Die").AddTime(mDeltaTime);
                    //mon_robot.Noeud.Position.x += 100f;
                    // Move.x += 100f;
                    break;
            }
            return true;
        }

		

		protected void statueAttaque()
		{
			List<Robot> robotsMorts = new List<Robot>();
			if (tailleStatue == tailleAttaque-1)
			{//previens les robots
				cercle.SetMaterialName("Examples/Rouge");
				foreach (Robot robot in Robots)
					robot.AttentionAttaqueStatue = true;
			}

			else if (tailleStatue==tailleAttaque)
			{
                //gere la taille du cercle
				cercle.SetMaterialName("Examples/FlyingLightMaterial");
                noeud_cercle.Scale(new Vector3(1f, 1.2f,1.2f));

				foreach (Robot robot in Robots)
				{
                    //tue les robots de son champ d'action
					Vector3 distance = statueOgreNode.Position - robot.Noeud.Position;
					float distanceF = distance.Normalise();
					if (distanceF <= tailleZoneOnde)
					{
						robotsMorts.Add(robot);
					}
                    robot.AttentionAttaqueStatue = false;
				}
				tailleZoneOnde += (tailleZoneOnde / 100) * 20;
				foreach (Robot robotASuppr in robotsMorts)
				{
					robotASuppr.Noeud.Parent.RemoveChild(robotASuppr.Noeud);
					Robots.Remove(robotASuppr);
				}
                tailleAttaque += 5;
                
			}
		}
    
    }
}